

'''
    需求：增加用例执行统计信息

'''
import  requests
import hashlib


#用例数据变量
total_test_case= 0
success_test_case= 0
fail_test_case= 0




with open('D:\\2.txt','r') as fp:
    b= fp.read().strip()


with open('D:\\2.txt','w') as fp:
    fp.write(str(int(b)+1)+'\n')

username= 'dfffkkkkk' + b
req= requests.post(url='http://101.42.247.45:8080/register/',
                  data='{"username":"%s","password":"12345678abc","email":"wxh@qq.com"}' %(username,))

print(9,req.text)
try:
    total_test_case+=1
    assert '{"code": "00"' in req.text
    success_test_case+=1
except Exception as e:
    fail_test_case+=1
    print('断言失败 %s' %'{"code": "00"')


m5= hashlib.md5()
m5.update('12345678abc'.encode('utf-8'))
pwd= m5.hexdigest()
print(pwd)



req= requests.post(url='http://101.42.247.45:8080/login/',
                  data='{"username":"%s","password":"%s","email":"wxh@qq.com"}' %(username,pwd,))
try:
    total_test_case+=1
    assert '{"code": "00"' in req.text
    success_test_case+=1
except Exception as e:
    fail_test_case+=1
    print('断言失败 %s' %'{"code": "00"')
#print(99,type(req.text))

import re
try:
    assert re.search(r'token": "\w{32}"',req.text)
except Exception as e:
    print('断言失败 %s' % '{"code": "00"')
#assert re.match(r"'token': ",req.text) in req.text

#接口响应的字符串内容
print(111,req.text)
#http协议状态码
print(2,req.status_code)

print(8,'*'*1000)
print('测试用例汇总')
print('一共执行测试用例%s个' %total_test_case)
print('成功执行测试用例%s个' % success_test_case)
print('失败执行测试用例%s个' %fail_test_case)














print(8,'*'*100)
print(req.json())#dict类型
print(type(req.json()))#dict类型
print(req.json()['code'])